package com.xtx.service.impl;

import com.xtx.entity.CategoryChildren;
import com.xtx.mapper.AllMapper;
import com.xtx.mapper.CategoryMapper;
import com.xtx.result.Result;
import com.xtx.service.AllService;
import com.xtx.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
@Slf4j
public class AllServiceImpl implements AllService {

    @Autowired
    private AllMapper allMapper;
    @Autowired
    private CategoryMapper categoryMapper;

    /*
    * 获取轮播图
     */
    @Override
    public List<HomeBannerVo> getHomeBanner(Integer id) {
        List<HomeBannerVo> homeBannerVoList= allMapper.getHomeBanner(id);
        return homeBannerVoList;
    }
    /*
    获取首页新鲜好物
     */
    @Override
    public List<HomeNewVo> getHomeNew() {
        List<HomeNewVo> homeNewVoList= allMapper.getHomeNew();
        return homeNewVoList;
    }

    /*
    获取首页人气推荐
     */
    @Override
    public List<HomeHotVo> getHomeHot() {
        List<HomeHotVo> homeHotVoList = allMapper.getHomeHot();
        return homeHotVoList;
    }

    /*
    获取首页随便看看
     */
    @Override
    public List<HomeCasualLookVo> getHomeCasualLook() {
        List<HomeCasualLookVo> homeCasualLookVoList = allMapper.getHomeCasualLook();
        return homeCasualLookVoList;
    }
    /*
    获取分类
     */
    @Override
    public List<CategoryHeaderVo> getCategoryApi() {
        log.info("获取头部分类");
        List<CategoryHeaderVo> list = categoryMapper.getCategoryApi();

        for (CategoryHeaderVo category : list) {
            // 根据父级ID查询子级数据
            List<CategoryChildren> children = categoryMapper.getCategoryChildrenById(category.getId());
            category.setChildren(children);
        }
        return list;
    }
}
